﻿using System;
using System.Collections.Generic;
using System.Text;
using Gammar.Digger.DALFactory;
using Gammar.Digger.Entity;
using Gammar.Digger.SystemFramework;
using Gammar.Digger.IDAL;
namespace Gammar.Digger.BLL
{
    public class SystemManagement
    {
        /// <summary>
        /// 获取所有状态为run的信息
        /// </summary>
        /// <returns></returns>
        public static SortList<System_statusEntity> GetSystemStatus()
        {
            ISystem_status status = DataAccess.CreateSystem_status();
            SortList<System_statusEntity> models= status.GetList("status=0 order by sys_id desc");
            return models;
        }

        /// <summary>
        /// 获取系统运行状态信息
        /// </summary>
        /// <param name="reval">返回描述信息</param>
        /// <param name="sysId">返回系统运行id</param>
        /// <returns></returns>
        public static bool GetLastSystemStatus(out string reval,out int sysId)
        {
            reval = "系统状态:";
            SortList<System_statusEntity> models = GetSystemStatus();
            if (models.Count>0)
            {
                reval += PluginsService.Status.Running.ToString();
                reval += "  开始时间:"+(new DateTime(models[0].start_time.Value)).ToString();
                reval += "  本次运行插件数:"+models[0].sum_plugins;
                sysId = models[0].sys_id.Value;
                return true;
            }
            else
            {
                reval += PluginsService.Status.Stopped.ToString();
                sysId = -1;
                return false;
            }
            
        }
    }
}
